//本代码为查询数据库，查询密码是否正确
//如果正确则返回success,token,用户信息
//如果不正确返回password error
//假设了表为sax，请自行替换
//密钥请自己更换，可以保证token单向性，如果需要时间，请增加一个token数据库和随机数发生器。
<?php
use RingCentral\Psr7\Response;

function handler($request, $context): Response{
    $body       = $request->getBody()->getContents();
    $data=json_decode($body,true); 
        $miyao="8p7LXQ3G0lCDz2QFXQblOs6O3NQOwyeo6W6CZ4zevi4VTMdX3lycBE0NTOgawqDy4Utl202QSiKdzID7Zmsh4QkHE559hSb3nq9s";
        $a="ssss";
        $pdo = new_pdo();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo->beginTransaction();
        $pdo->commit();
        $stmt = $pdo->query("SELECT password,accountid,message FROM sxa
                            WHERE phonenumber= $data[phonenumber]");
        while ($row = $stmt->fetch()) {
            $a = $row['password'];
            $accountid = $row['accountid'];
            $message=$row['message'];
        }
        if($data['password']==$a){
            $token=md5($accountid.md5($accountid.$miyao).$miyao);
        $arr=array('login_code'=>"success",'accountid'=>$accountid,'message'=>$message,'token'=>$token);}
        else{$arr=array('login_code'=>"password error");}
        $b=json_encode($arr);

    return new Response(
        200,
        array(
            'custom_header1' => 'v1',
            'custom_header2' => ['v2', 'v3'],
        ),
        $b
    );
}

//自己数据库的信息
function new_pdo()
{
    $mysql_host = "xxx";
    $mysql_port = "xxx";
    $mysql_user = "xxxx";
    $mysql_password = "xxxx";
    $mysql_dbname = "xxxx";
    return new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_dbname", $mysql_user, $mysql_password);
}